//
//  UserBaseVC.m
//  licai
//
//  Created by Rajon on 15/12/2.
//  Copyright © 2015年 Boye. All rights reserved.
//

#import "UserBaseVC.h"

@interface UserBaseVC ()

@end

@implementation UserBaseVC


- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 创建_scrollView
    [self _createScrollView];
    // 创建导航栏左边返回按钮
    [self createLeftBarButtonItem];
}
#pragma mark - 创建_scrollView
// 创建_scrollView
- (void)_createScrollView
{
    _scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    _scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_scrollView];
}

#pragma mark - 键盘弹出时执行，使编辑栏随键盘上升变成可以滑动（覆写父类方法）
- (void)keyboardFrameChange:(NSNotification *)notification
{
    [super keyboardFrameChange:notification];
    //获取键盘的frame
    NSValue *boundsValue = [notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect frame = [boundsValue CGRectValue];
    //键盘y值
    CGFloat y = frame.origin.y;
    //调整_scrollView可滑动范围
    NSArray *subviews = _scrollView.subviews;
    UIView *lastSubview = nil;
    for (NSInteger i = subviews.count-1; i >= 0; i --) {
        if ([subviews[i] isKindOfClass:[UIButton class]]) {
            lastSubview = subviews[i];
            break;
        }
    }
    // 如果最底下的按钮被键盘遮挡，则按遮挡的高度增加相应的_scrollView的可滑动范围
    if (lastSubview.bottom - y > -50) {
        CGFloat distance = lastSubview.bottom - y;
        _scrollView.contentSize = CGSizeMake(self.view.width, self.view.height + distance + 40);
    }
}


#pragma mark
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
